package com.abe.libquick.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

public class CusScrollView extends ScrollView {
    private ScrollViewListener scrollViewListener = null;
    private ISmartScrollChangedListener mSmartScrollChangedListener;

    public CusScrollView(Context context) {
        super(context);
    }

    public CusScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CusScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setScanScrollChangedListener(ISmartScrollChangedListener smartScrollChangedListener) {
        mSmartScrollChangedListener = smartScrollChangedListener;
    }

    public void setScrollViewListener(ScrollViewListener scrollViewListener) {
        this.scrollViewListener = scrollViewListener;
    }

    @Override
    protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
        super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
        if (mSmartScrollChangedListener != null) {
            mSmartScrollChangedListener.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
        }
    }

    @Override
    protected void onScrollChanged(int x, int y, int oldx, int oldy) {
        super.onScrollChanged(x, y, oldx, oldy);
        if (scrollViewListener != null) {
            scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
        }
        if (mSmartScrollChangedListener != null) {
            mSmartScrollChangedListener.onScrollChanged(x, y, oldx, oldy);
        }
    }

    public interface ScrollViewListener {

        void onScrollChanged(CusScrollView scrollView, int x, int y, int oldx, int oldy);
    }

    //定义监听接口
    public interface ISmartScrollChangedListener {

        void onScrollChanged(int l, int t, int oldl, int oldt);

        void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY);
    }
}